package org.pcorp.battlespace.construction.ui.sub.armement;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import org.pcorp.battlespace.construction.modele.SabordCstr;
import org.pcorp.battlespace.modele.Element;

public class ArmTreeCellRenderer extends DefaultTreeCellRenderer {
	private static final long serialVersionUID = 7400888389061048921L;


	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, sel,expanded, leaf, row,hasFocus);
		setText(getLabel(value));
		return this;
	}


	protected String getLabel(Object value) {
		DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
		if (node.getUserObject() instanceof SabordCstr) {
			SabordCstr nodeInfo = (SabordCstr)(node.getUserObject());
			return nodeInfo.getLabel().concat(" ").concat(Long.toString(nodeInfo.getEmplacementDispo())).concat("/").concat(Long.toString(nodeInfo.getEmplacementMax()));
		}
		if (node.getUserObject() instanceof Element) {
			Element nodeInfo = (Element)(node.getUserObject());
			return nodeInfo.getLabel();
		}
		return "erreur";
	}


	@Override
	public Color getBackgroundNonSelectionColor() {
		return null;
	}
	
	@Override
	public Color getBackground() {
		return null;
	}
	
}
